package com.lyc.controller.admin;

import com.lyc.DTO.ItemTypeDTO;
import com.lyc.pojo.ItemType;
import com.lyc.pojo.Result;
import com.lyc.service.ItemTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/admin/itemType")
public class ItemTypesController {
    
    @Autowired
    private ItemTypeService itemTypeService;
    
    // 获取分类列表
    @GetMapping()
    public Result<List<ItemType>> getItemTypes() {
        List<ItemType> itemTypes = itemTypeService.getItemTypes();
        return Result.success(itemTypes);
    }
    
    // 添加分类
    @PostMapping(value = "/add")
    public Result addItemType(@RequestBody ItemTypeDTO itemTypeDTO) {
        itemTypeService.addItemType(itemTypeDTO);
        return Result.success();
    }
    
    // 更新分类
    @PutMapping(value = "/update")
    public Result updateItemType(@RequestBody ItemTypeDTO itemTypeDTO) {
        itemTypeService.updateItemType(itemTypeDTO);
        return Result.success();
    }
    
    // 删除分类
    @DeleteMapping(value = "/delete")
    public Result deleteItemType(@RequestParam Integer id) {
        itemTypeService.deleteItemType(id);
        return Result.success();
    }
    
    // 更新分类状态
    @PatchMapping(value = "/status")
    public Result updateItemTypeStatus(@RequestParam Integer id, @RequestParam String status) {
        itemTypeService.updateItemTypeStatus(id, status);
        return Result.success();
    }
}